<template>
  <div>
    <tree-grid :columns="columns" :tree-structure="true" :data-source="dataSource" v-on:updateStateValue="updateStateValue"></tree-grid>
  </div>
</template>
<script>
import TreeGrid from '../../components/system/treeTable/vue/TreeGrid'

export default {
  name: 'department',
  data () {
    return {
      columns: [
        {
          text: '部门',
          dataIndex: 'deptName',
          align: 'left'
        },
        {
          text: '地址',
          dataIndex: 'deptAddress',
          align: 'center'
        },
        {
          text: '电话',
          dataIndex: 'deptPhone',
          align: 'center'
        },
        {
          text: '邮箱',
          dataIndex: 'deptEmail',
          align: 'center'
        }
      ],
      dataSource: []
    }
  },
  components: {
    TreeGrid
  },
  methods: {
    getDeptInfos: function () {
      let url = this.$base.getUrl('getDeptInfos')
      let params = {
        url: url,
        data: {}
      }
      this.$store.dispatch('getForm', params).then(res => {
        if (res) {
          this.dataSource = res.nodes
        }
      })
    },
    updateStateValue (val) {
      if (val) {
        this.getDeptInfos()
      }
    }
  },
  mounted () {
    this.getDeptInfos()
  }
}
</script>
